package 笔试.隽思信息;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class 海域数量 {
    public static int[][] dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] split = line.trim().split(",");
        int n = Integer.parseInt(split[0]);
        int m = Integer.parseInt(split[1]);
        int[][] matrix = new int[n][m];
        Queue<int[]> queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            line = sc.nextLine();
            split = line.trim().split(",");
            for (int j = 0; j < split.length; j++) {
                matrix[i][j] = Integer.parseInt(split[j]);
                if (matrix[i][j] == 1) queue.add(new int[]{i, j});
            }
        }
        // 4,5
        // 1,1,0,0,0
        // 1,0,1,0,0
        // 1,0,0,0,0
        // 1,1,0,1,1
        boolean[][] visited = new boolean[n][m];
        int ans = 0;
        while (!queue.isEmpty()) {
            int[] poll = queue.poll();
            int x = poll[0];
            int y = poll[1];
            if (visited[x][y]) {
                continue;
            }
            Queue<int[]> bfsQueue = new LinkedList<>();
            bfsQueue.add(new int[]{x, y});
            while (!bfsQueue.isEmpty()) {
                int[] bfspoll = bfsQueue.poll();
                int bfsx = bfspoll[0];
                int bfsy = bfspoll[1];
                if (visited[bfsx][bfsy]) {
                    continue;
                }
                visited[bfsx][bfsy] = true;
                for (int i = 0; i < 4; i++) {
                    int tx = bfsx + dir[i][0];
                    int ty = bfsy + dir[i][1];
                    if (tx < 0 || tx >= n || ty < 0 || ty >= m) {
                        continue;
                    }
                    if (visited[tx][ty] || matrix[tx][ty] == 0) {
                        continue;
                    }
                    bfsQueue.add(new int[]{tx, ty});
                }
            }
            ans++;
        }
        System.out.println(ans);
    }
}
